package icegps.com.pingdj.map.utils;

import android.os.Environment;

import java.io.File;
import java.io.IOException;

import icegps.com.pingdj.App;

/**
 * Created by 111 on 2018/3/29.
 */

public class FileUtils {
    private final static String BASE_DIR = "BASE_DIR";
    public final static String BITMAP_DIR = "BITMAP_DIR";
    public final static String ARRAY_DATA_DIR = "ARRAY_DATA_DIR";


    private static File getBaseDir() {
        File cacheDir = Environment.getExternalStorageDirectory();
        File baseDir = new File(cacheDir, BASE_DIR);
        if (!baseDir.exists())
            baseDir.mkdirs();
        return baseDir;
    }

    public static File getFile(String dir, long token, String fileName) {
        File baseDir = getBaseDir();
        File file = new File(baseDir, dir + "/" + token);
        if (!file.exists())
            file.mkdirs();
        File f = new File(file, fileName);
        if (!f.exists())
            try {
                f.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        return f;
    }

    public static File getDir(String dir, long token) {
        File baseDir = getBaseDir();
        File file = new File(baseDir, dir + "/" + token);
        if (!file.exists())
            file.mkdirs();
        return file;
    }
}
